package cz.muni.fi.pa165.languageschool.rest.client.app;

/**
 * This class is used for manipulation with students
 *
 * @author Milos
 */
class Students {

    SchoolApp app;
    Student student;
    String resourceBase;

    /**
     * Constructor of the class Students
     *
     * @param app represents application to which students belongs
     */
    public Students(SchoolApp app, String base) {
        this.app = app;
        this.resourceBase = base;
        student = new Student(this, resourceBase);
    }

    /**
     * Method select() is used for choosing action which can be preformed q -
     * quit, b - back, n - new student, d - delete student, u - update student
     *
     */
    public void select() {
        while (app.running) {
            Helper.clear();
            student.printStudents();
            printHelp();
            Object resp = Helper.getResponse("Choose", "q", "b", "n", "d", "u", Integer.class);
            if (resp == null) {
                return;
            }
            //if(resp != null)
            {
                if ("q".equals(resp)) {
                    app.running = false;
                } else if ("b".equals(resp)) {
                    return;
                } else if ("n".equals(resp)) {
                    student.newStudent();
                } else if ("d".equals(resp)) {
                    student.deleteStudent();
                } else if ("u".equals(resp)) {
                    student.updateStudent();

                } else {
                    Integer id = (Integer) resp;
                    student.printStudent(id);
                }

            }
        }
    }

    /**
     * This method prints help on standard output
     */
    private void printHelp() {
        System.out.println("_____");
        System.out.println("q - Exit");
        System.out.println("b - Back");
        System.out.println("n - New student");
        System.out.println("d - Delete student");
        System.out.println("u - Update student");
        System.out.println("Number - Go to student with id = Number you set ");

    }
}
